package com.kfpanda.search.action.searchmg;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.apache.lucene.document.Document;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.kfpanda.search.action.BaseAction;
import com.kfpanda.search.biz.searchmg.SearchBIZ;
import com.kfpanda.search.entity.SearchField;
import com.util.common.page.PageImp;

@Repository
@Controller
@Scope("prototype")
public class SearchAction extends BaseAction {
	@Resource
	private SearchBIZ searchBIZ;
	
	@RequestMapping("/search/list.htm")
	public String fileSearch(ModelMap model, @RequestParam String queries, @ModelAttribute PageImp paging, 
			@RequestParam(required=false) String field){
		SearchField searchField = new SearchField();
		searchField.setQueries(queries);
		if( !StringUtils.isBlank(field) ){
			searchField.setField(field);
		}
		List<Document> docList = searchBIZ.fileSearch(searchField, paging);
		model.put("docList", docList);
		model.put("paging", paging);
		return "search/page";
	}
}
